// File Name: usart_interface.h
// Author: kukukukuku~
// Date: 2024-12-21

#ifndef __USART_INTERFACE_H
#define __USART_INTERFACE_H

#include "./USART/inc/usart_ctrl.h"
#include "./USART/inc/usart_init.h"

//USART接收状态
typedef enum USART_RX_STATE_T
{
    USART_RX_STATE_UNCOMPLETE = 0,
    USART_RX_STATE_COMPLETE = !USART_RX_STATE_UNCOMPLETE,
}USART_RX_STATE_T;

//USART对象
typedef struct USART_OBJECT_T
{
    uint8_t *pTxBuffer;
    uint8_t *pRxBuffer;
    uint16_t rxIndex;
    USART_RX_STATE_T rxFinishFlag;
}USART_OBJECT_T, *pUSART_OBJECT_T;


void usart_object_init(USART_OBJECT_T * const usartObj, const uint8_t * const txBuffer, const uint8_t * const rxBuffer);

void usart_int_idle_callback(USART_OBJECT_T * const usartObj);
void usart_int_rx_callback(USART_OBJECT_T * const usartObj);

void usart_rx_finish_flag_clear(USART_OBJECT_T * const usartObj);
USART_RX_STATE_T usart_rx_finish_flag_get(const USART_OBJECT_T * const usartObj);

void usart_rx_data_len_clear(USART_OBJECT_T * const usartObj);
uint16_t usart_rx_data_len_get(const USART_OBJECT_T * const usartObj);

void usart_received_data_handle(USART_OBJECT_T * const usartObj);
uint8_t * usart_rx_buffer_get(const USART_OBJECT_T * const usartObj);
void usart_rx_buffer_clear(USART_OBJECT_T * const usartObj);
void usart_send_data(USART_OBJECT_T * const usartObj, const uint8_t * const data, const uint16_t dataLen);

#endif //__USART_INTERFACE_H
